<?php
$i = 1;
?>

<table class="tborder" cellspacing="1" cellpadding="4" border="0">
    <thead>
        <tr>
            <td class="thead" colspan="5">
                    <div class="expcolimage">
                        <img alt="[-]" class="expander" src="img/collapse.gif" style="cursor: pointer;" id="expander">
                    </div>

                    <div>
                        <strong><?php echo $forum->name; ?></strong>
                        <br />
                        <div class="smalltext"></div>
                    </div>
            </td>
        </tr>
    </thead>

    <tbody id="tbody">
        <tr>
            <td class="tcat" width="35">&nbsp;</td>
            <td class="tcat"><strong>Forum</strong></td>
            <td class="tcat" width="85" align="center" style="white-space: nowrap;"><strong>Replies</strong></td>
            <td class="tcat" width="85" align="center" style="white-space: nowrap;"><strong>Views</strong></td>
            <td class="tcat" width="200" align="center"><strong>Last post</strong></td>
        </tr>

<?php
// Check if a topic at least exists
if(isset($topics) && !empty($topics)) {
    foreach ($topics as $topic) {
        $rowColor = ($i++ % 2 == 0) ? 'trow1' : 'trow2' ;
    ?>

        <tr>
            <td class="<?php echo $rowColor; ?>" valign="top" align="center">
                &nbsp;
            </td>
            <td class="<?php echo $rowColor; ?>" valign="top">
                <strong>
                    <a href="<?php echo __route('ml-forum/topics/show&t='.$topic->id); ?>">
                        <?php echo $topic->subject; ?>
                    </a>
                </strong>
            </td>
            <td class="<?php echo $rowColor; ?>" valign="top" align="center" style="white-space: nowrap;">
                <?php echo $topic->num_replies; ?>
            </td>
            <td class="<?php echo $rowColor; ?>" valign="top" align="center" style="white-space: nowrap;">
                <?php echo $topic->num_views; ?>
            </td>
            <td class="<?php echo $rowColor; ?>" valign="top" style="white-space: nowrap;">
                <a href="<?php echo __route('ml-forum/topics/show&t='.$topic->post->topic_id.'#pid'.$topic->post->id); ?>">
                    <?php echo (strlen($topic->post->message) > '26') ? substr($topic->post->message, '0', '26').' [...]' : $topic->post->message ; ?>
                </a>
            </td>
        </tr>

    <?php
    } // end foreach
} else {
?>

    <tr>
        <td class="trow1" colspan="5" valign="top" style="white-space: nowrap;" text-align="center;">
            <div align="center"><?php echo __t('mandrill.forum.topics.empty', array(), 'ml-forum', 'modules'); ?></div>
        </td>
    </tr>

<?php
} // end else
?>
    
    </tbody>
</table>
<br />

<?php
// Render the create button
if(MSession::getInstance()->isLogged()) {
    echo __tag('a', array('class'=>'button', 'href'=>__route('ml-forum/topics/create&f='.$forum->id)), __t('mandrill.forum.topic.create', NULL));
}
?>
<br />
<br />